/**--------------------------------------------------------------------------
 * Author: lvzeyuan@126.com
 * Date: 2017.10.10
 * Description: 站点相关全局配置及公用函数文件
 *
 * History:
 -------------------------------------------------------------------------*/


//#region ---------------------------------------------------------全局配置

var SiteConfig = {};

SiteConfig.webApi = 'http://iot.hzcando.com:10004/api/idm/';
SiteConfig.webApiset = 'http://iot.hzcando.com:10004';

//
// SiteConfig.webApiset = 'http://localhost:10004';
// SiteConfig.webApi = 'http://localhost:10004/api/idm/v1/';


SiteConfig.chartColors = ['#FF3D50', '#FFC526', '#03BAFB', '#12E266', '#00E7D4'];
SiteConfig.account = {
    CompanyCode: '',
    CompanyLogo: '',
    CompanyName: '',
    id: '',//当前登录用户ID
    systemTitle: '',
    accesstoken: '', //访问令牌
    expiresIn: 0, //失效时间
    refreshtoken: '',
    roleId: '',
    uId: '', //全局唯一标识
    loginTime: '',//登录时间
    userName: '',
    projectNo: '',
    zone: ''
};


SiteConfig.Menu_syf = [
    // {
    //     name: '大屏首页',
    //     index: '1',
    //     url: 'pages/prevention/user-visual/index.html',
    //     icon: 'icon-home'
    // },
    {
        name: '实时监测',
        index: '6',
        icon: 'icon-monitor',
        url: "pages/prevention/device-monitor/realtime-monitor.html",
    },

    {
        name: '员工奖惩台账',
        index: '3',
        icon: 'icon-report',
        child: [
            {
                name: '员工奖惩台账',
                url: 'pages/prevention/reward-manage/riskreward.html',
                index: '3-1'
            },
        ]
    },
    {
        name: '风险管理',
        index: '6',
        icon: 'icon-alarm-ana',
        child: [
            {
                name: '风险识别',
                url: 'pages/prevention/risk-manage/risk-identification.html',
                index: '6-1'
            },
            {
                name: "风险作业比较图",
                url: 'pages/prevention/risk-manage/risk-compare.html',
                index: '6-2'
            },
            {
                name: '风险责任清单',
                url: 'pages/prevention/risk-manage/risk-responsibility.html',
                index: '6-3'
            },
            {
                name: '风险研判标准',
                url: 'pages/prevention/risk-manage/risk-standard.html',
                index: '6-4'
            },
        ]
    },
    {
        name: '风险隐患台账',
        index: '9',
        url: 'pages/prevention/warning-manage/warningbill.html',
        icon: 'icon-ele-ana'
    },
    {
        name: '系统设置 ',
        index: '11',
        icon: 'icon-dev',
        child: [
            {
                name: '工种管理',
                url: 'pages/prevention/system-manage/worktype.html',
                index: '11-1'
            },
            {
                name: '区域管理',
                url: 'pages/prevention/system-manage/zone-manage.html',
                index: '11-2'
            },
            {
                name: '作业管理',
                url: 'pages/prevention/system-manage/workflow.html',
                index: '11-3'
            },
            {
                name: '设备管理',
                url: 'pages/prevention/system-manage/collector-manage.html',
                index: '11-4'
            }, {
                name: '场景设置',
                url: 'pages/prevention/system-manage/scene-manage.html',
                index: '11-5'
            }, {
                name: '风险点位置',
                url: 'pages/prevention/system-manage/riskpoint-localtion.html',
                index: '11-6'
            }, {
                name: '设备位置',
                url: 'pages/prevention/system-manage/devmap-manage.html',
                index: '11-7'
            },
            {
                name: '视频管理',
                url: 'pages/prevention/video-manage/video-manage.html',
                index: '11-8'
            }, {
                name: '四色图',
                url: 'pages/prevention/system-manage/map-marker.html',
                index: '11-9'
            }
        ]
    }
];


SiteConfig.Menu_Safe = [

    {
        name: '校园机构管理台账',
        index: '2',
        icon: 'icon-network',
        child: [
            {
                name: '学校部门管理',
                index: '2-1',
                url: 'pages/prevention/personnel-manage/organization.html'
            }, {
                name: '校园账户管理',
                index: '2-2',
                url: 'pages/prevention/personnel-manage/employees.html'
            }, {
                name: '班级信息管理',
                index: '2-3',
                url: 'pages/prevention/personnel-manage/classes.html'
            }, {
                name: '职工信息管理',
                index: '2-4',
                url: 'pages/prevention/personnel-manage/staffs.html'
            },{
               name:'职工证件信息',
                index:'2-5',
                url:'pages/prevention/personnel-manage/worker-detail.html'

            }
        ]
    },
    {
        name: '校园安全台账',
        index: '4',
        icon: 'icon-energy-sum',
        child: [
            {
                name: '校园设施台帐',
                index: '4-1',
                url: 'pages/prevention/safebill-manage/devicesbill.html'
            }, {
                name: '校园危险源台帐',
                index: '4-2',
                url: 'pages/prevention/safebill-manage/risksourcebill.html'
            }, {
                name: '校园消防设备台账',
                index: '4-3',
                url: 'pages/prevention/safebill-manage/firebill.html'
            }, {
                name: '校园三违登记台账',
                index: '4-4',
                url: 'pages/prevention/safebill-manage/threeviolate.html'
            }
        ]
    },
    {
        name: '校园隐患排查',
        index: '7',
        icon: 'icon-alarm-ana',
        child: [
            {
                name: '风险巡查',
                url: 'pages/prevention/hiddendanger-manage/riskpatrol.html',
                index: '7-1'
            },
            {
                name: '风险巡查历史记录',
                url: 'pages/prevention/hiddendanger-manage/riskpatrolHistory.html',
                index: '7-2'
            },
            {
                name: '风险统计',
                url: 'pages/prevention/hiddendanger-manage/riskpercent.html',
                index: '7-3'
            },
        ]
    },
    {
        name: '校园考勤',
        index: '8',
        icon: 'icon-alarm-ana',
        child: [
            {
                name: '考勤情况',
                url: 'pages/prevention/check-manage/check-detail.html',
                index: '8-1'
            },
            {
                name: '考勤机管理',
                url: 'pages/prevention/check-manage/check-machine.html',
                index: '8-2'
            },
            {
                name: '考勤时段设置',
                url: 'pages/prevention/check-manage/check-setting.html',
                index: '8-3'
            },
        ]
    },
    {
        name: '安全物联',
        index: '10',
        icon: 'icon-opera',
        child: [

            {
                name: '实时视频',
                url: 'pages/prevention/video-manage/video-show.html',
                index: '10-1'
            },
            {
                name: '设备监测',
                url: 'pages/prevention/device-monitor/devMonitor.html',
                index: '10-2'
            }
        ]
    },
];


SiteConfig.Menu_Emergency = [
    {
        name: '通知公告',
        index: '1',
        url: 'pages/404/index.html',
        icon: 'icon-report',
        child: [
            {
                name: '发通知',
                index: '1-1',
                url: 'pages/prevention/notice-manage/send-notice.html',
            },
            {
                name: '收件箱',
                index: '1-2',
                url: 'pages/prevention/notice-manage/revice-notice.html',
            },
        ]
    },
    {
        name: '应急管理',
        index: '5',
        icon: 'icon-energy-sum',
        child: [
            {
                name: '应急广播',
                index: '5-1',
                url: 'pages/prevention/contingency-manage/radio.html'
            },
            {
                name: '疏散图管理',
                index: '5-10',
                url: 'pages/prevention/contingency-manage/Map.html'
            },
            {
                name: '预案管理',
                index: '5-2',
                url: 'pages/prevention/contingency-manage/Preplan.html'
            },
            // {
            //     name: '预案考核管理',
            //     index: '5-3',
            //     url: 'pages/prevention/contingency-manage/plan_exam.html'
            // },
            {
                name: '物资分类',
                index: '5-4',
                url: 'pages/prevention/contingency-manage/EmergenceSupplies.html'
            }, {
                name: '应急物资管理',
                index: '5-5',
                url: 'pages/prevention/contingency-manage/EmergenceManage.html'
            }
            , {
                name: '应急物资配备',
                index: '5-6',
                url: 'pages/prevention/contingency-manage/EmergenceEquipment.html'
            }
            , {
                name: '应急演练计划',
                index: '5-7',
                url: 'pages/prevention/contingency-manage/drillPlan.html'
            }
        ]
    },
    {
        name: '应急培训',
        index: '8',
        icon: 'icon-exit',
        child: [
            {
                name: '培训计划',
                url: 'pages/prevention/risk-train/trainplan.html',
                index: '8-1'
            },
            {
                name: '培训资料',
                url: 'pages/prevention/risk-train/trainword.html',
                index: '8-2'
            },
        ]
    },
    {
        name: '预警分析',
        index: '9',
        url: 'pages/prevention/warning-manage/alarm-list.html',
        icon: 'icon-ele-ana'
    },
];


SiteConfig.Menu_edu = [
    // {
    //     name: '安全资源',
    //     index: '10',
    //     child: [
    //
    //         {
    //             name: '安全知识',
    //             url: 'pages/404/index.html',
    //             index: '10-1'
    //         },
    //         {
    //             name: '校本资源',
    //             url: 'pages/404/index.html',
    //             index: '10-2'
    //         }
    //     ]
    // },
    // {
    //     name: '危险品名录',
    //     url: 'pages/gover/safebaike-manage/DangerousContent.html',
    //     index: '12',
    //     icon: 'icon-ele-ana'
    // },
    // {
    //     name: '法律法规',
    //     url: 'pages/gover/safebaike-manage/GovernmentLaw.html',
    //     index: '13',
    //     icon: 'icon-report'
    // },
    // {
    //     name: '危险化工工艺',
    //     url: 'pages/gover/safebaike-manage/GovernmentCraft.html',
    //     index: '14',
    //     icon: 'icon-energy-sum'
    // },
    // {
    //     name: '危险品应急处置',
    //     url: 'pages/gover/safebaike-manage/EmergencyResponseAdd.html',
    //     index: '15',
    //     icon: 'icon-monitor'
    // },
    // {
    //     name: '矿山风险应急处置',
    //     url: 'pages/gover/safebaike-manage/RiskMeasures.html',
    //     index: '16',
    //     icon: 'icon-alarm-ana'
    // },
    // {
    //     name: '安全生产规范',
    //     url: 'pages/gover/safebaike-manage/SafeProduction.html',
    //     index: '17',
    //     icon: 'icon-opera'
    // },
    {
        name: '疫情上报统计',
        url: 'pages/prevention/safebill-manage/erstatistics.html',
        index: '12',
        icon: 'icon-ele-ana'
    },
    {
        name: '疫情统计',
        url: 'pages/prevention/safebill-manage/estatistics.html',
        index: '13',
        icon: 'icon-report'
    },
    {
        name: '病例统计',
        url: 'pages/prevention/safebill-manage/casestatistics.html',
        index: '14',
        icon: 'icon-energy-sum'
    },
    {
        name: '师生健康档案',
        url: 'pages/prevention/safebill-manage/healthfile.html',
        index: '15',
        icon: 'icon-monitor'
    }

]
SiteConfig.Menu_fill = [
    {
        name: '学校基本信息',
        url: 'pages/prevention/fill-manage/baseinfo.html',
        index: '12',
        icon: 'icon-ele-ana'
    },
    {
        name: '安全月报',
        url: 'pages/prevention/fill-manage/safemonthreport.html',
        index: '13',
        icon: 'icon-report'
    },
    {
        name: '安全事故管理',
        url: 'pages/prevention/fill-manage/safehitch.html',
        index: '14',
        icon: 'icon-energy-sum'
    },
    {
        name: '伤亡信息登记',
        url: 'pages/prevention/fill-manage/casualtiesinfo.html',
        index: '15',
        icon: 'icon-monitor'
    },
    // {
    //     name: '突发隐患登记',
    //     url: 'pages/prevention/fill-manage/baseinfo.html',
    //     index: '16',
    //     icon: 'icon-alarm-ana'
    // },
    {
        name: '安全教育计划',
        url: 'pages/prevention/fill-manage/safeeduproject.html',
        index: '16',
        icon: 'icon-alarm-ana'
    },
    {
        name: '安全培训记录',
        url: 'pages/prevention/fill-manage/safetraining.html',
        index: '17',
        icon: 'icon-alarm-ana'
    },
    {
        name: '安全授课记录',
        url: 'pages/prevention/fill-manage/safeteach.html',
        index: '18',
        icon: 'icon-alarm-ana'
    },
    // {
    //
    //     name: '安全百科',
    //     index: '12',
    //     icon: 'icon-report',
    //     child: [
    //         {
    //             name: '危险品名录',
    //             url: 'pages/gover/safebaike-manage/DangerousContent.html',
    //             index: '12-1'
    //         },
    //         {
    //             name: '法律法规',
    //             url: 'pages/gover/safebaike-manage/GovernmentLaw.html',
    //             index: '12-2'
    //         },
    //         {
    //             name: '危险化工工艺',
    //             url: 'pages/gover/safebaike-manage/GovernmentCraft.html',
    //             index: '12-3'
    //         },
    //         {
    //             name: '危险品应急处置',
    //             url: 'pages/gover/safebaike-manage/EmergencyResponseAdd.html',
    //             index: '12-4'
    //         },
    //         {
    //             name: '矿山风险应急处置',
    //             url: 'pages/gover/safebaike-manage/RiskMeasures.html',
    //             index: '12-5'
    //         },
    //         {
    //             name: '安全生产规范',
    //             url: 'pages/gover/safebaike-manage/SafeProduction.html',
    //             index: '12-6'
    //         },
    //     ]
    // },
]
SiteConfig.Menu_broadcast = [
    {
        name: '今日广播',
        url: 'pages/prevention/broadcast-manage/todaybroadcast.html',
        index: '12',
        icon: 'icon-ele-ana'
    },
    {
        name: '即时广播',
        url: 'pages/prevention/broadcast-manage/timelybroadcast.html',
        index: '13',
        icon: 'icon-report'
    },
    {
        name: '作息广播',
        url: 'pages/prevention/broadcast-manage/workbroadcast.html',
        index: '14',
        icon: 'icon-energy-sum'
    },
    {
        name: '广播历史',
        url: 'pages/prevention/broadcast-manage/historybroadcast.html',
        index: '15',
        icon: 'icon-monitor'
    },
    // {
    //     name: '突发隐患登记',
    //     url: 'pages/prevention/fill-manage/baseinfo.html',
    //     index: '16',
    //     icon: 'icon-alarm-ana'
    // },
    // {
    //     name: '公共广播资源',
    //     url: 'pages/prevention/broadcast-manage/publicbroadcast.html',
    //     index: '16',
    //     icon: 'icon-alarm-ana'
    // },
    {
        name: '作息表设置',
        url: 'pages/prevention/broadcast-manage/worktime.html',
        index: '17',
        icon: 'icon-alarm-ana'
    },
    // {
    //     name: '广播模板',
    //     url: 'pages/prevention/broadcast-manage/broadcasttemplate.html',
    //     index: '18',
    //     icon: 'icon-alarm-ana'
    // },
    {
        name: '广播库',
        url: 'pages/prevention/broadcast-manage/audiolibrary.html',
        index: '19',
        icon: 'icon-alarm-ana'
    },
    // {
    //
    //     name: '安全百科',
    //     index: '12',
    //     icon: 'icon-report',
    //     child: [
    //         {
    //             name: '危险品名录',
    //             url: 'pages/gover/safebaike-manage/DangerousContent.html',
    //             index: '12-1'
    //         },
    //         {
    //             name: '法律法规',
    //             url: 'pages/gover/safebaike-manage/GovernmentLaw.html',
    //             index: '12-2'
    //         },
    //         {
    //             name: '危险化工工艺',
    //             url: 'pages/gover/safebaike-manage/GovernmentCraft.html',
    //             index: '12-3'
    //         },
    //         {
    //             name: '危险品应急处置',
    //             url: 'pages/gover/safebaike-manage/EmergencyResponseAdd.html',
    //             index: '12-4'
    //         },
    //         {
    //             name: '矿山风险应急处置',
    //             url: 'pages/gover/safebaike-manage/RiskMeasures.html',
    //             index: '12-5'
    //         },
    //         {
    //             name: '安全生产规范',
    //             url: 'pages/gover/safebaike-manage/SafeProduction.html',
    //             index: '12-6'
    //         },
    //     ]
    // },
]

//百度地图样式
SiteConfig.mapStyle = {
    styleJson: [
        {
            "featureType": "water",
            "elementType": "all",
            "stylers": {
                "color": "#00141E"
            }
        },
        {
            "featureType": "land",
            "elementType": "all",
            "stylers": {
                "color": "#00263A"
            }
        },
        {
            "featureType": "boundary",
            "elementType": "geometry",
            "stylers": {
                "color": "#064f85"
            }
        },
        {
            "featureType": "railway",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "highway",
            "elementType": "geometry",
            "stylers": {
                "color": "#004981"
            }
        },
        {
            "featureType": "highway",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#005b96",
                "lightness": 1
            }
        },
        {
            "featureType": "highway",
            "elementType": "labels",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "arterial",
            "elementType": "geometry",
            "stylers": {
                "color": "#004981"
            }
        },
        {
            "featureType": "arterial",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#00508b"
            }
        },
        {
            "featureType": "poi",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "green",
            "elementType": "all",
            "stylers": {
                "color": "#056197",
                "visibility": "off"
            }
        },
        {
            "featureType": "subway",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "manmade",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "local",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "arterial",
            "elementType": "labels",
            "stylers": {
                "visibility": "off"
            }
        },
        {
            "featureType": "boundary",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#029fd4"
            }
        },
        {
            "featureType": "building",
            "elementType": "all",
            "stylers": {
                "color": "#1a5787"
            }
        },
        {
            "featureType": "label",
            "elementType": "all",
            "stylers": {
                "visibility": "off"
            }
        }
    ]
};


//从缓存中恢复账户信息
var userAccount = sessionStorage.getItem('user-account');
if (userAccount) {
    SiteConfig.account = JSON.parse(userAccount);
}
;

//从缓存中恢复菜单
var userMenu = sessionStorage.getItem('user-menu');
if (userMenu) {
    SiteConfig.menu = JSON.parse(userMenu);
}
;

//#endregion


//#region ---------------------------------------------------------公用函数，其它服务端api调用写在各自页面内

//判断用户是否已经登录
function isLogined() {
    if (SiteConfig.account.uId &&
        (new Date().getTime() - new Date(SiteConfig.account.loginTime).getTime()) < SiteConfig.account.expiresIn) {

        return true;
    }
    return false;
}

function userLogin(username, password) {
    var _this = this;
    if (this.isLogined()) {

        return {
            "success": function (callback) {
                callback({state: 0});
            }
        };
    }

    return {
        "success": function (callback) {
            HttpUtil.get('oauth2/accessToken', {
                client_id: username,
                client_secret: password,
                scope: 'read,write'
            }).success(function (resData) {
                var data = resData.data;
                SiteConfig.account = {
                    CompanyCode: data.CompanyCode,
                    companyLogo: SiteConfig.webApiset + data.CompanyLogo,
                    companyName: data.CompanyName,
                    id: data.Id,
                    systemTitle: data.SystemTitle,
                    accessToken: data.access_token,
                    expiresIn: data.expires_in * 1000, //毫秒
                    refreshToken: data.refresh_token,
                    roleId: data.roleId,
                    uId: data.uid, //当前会话token对应的唯一
                    loginTime: TimeUtil.convertToString(new Date()),
                    userName: username,
                    projectNo: data.defaultProjectNo,
                    zone: data.zone
                };
                // HttpUtil.get('Menu/getMenuTree',{UserId:SiteConfig.account.id,rootId:0}).success(function(menuData){
                //     SiteConfig.menu = parseMenu(menuData.data,1);
                //     // for (let i in SiteConfig.menu){
                //     //     SiteConfig.menu[i].icon= 'icon-alarm-ana';
                //     // }
                //     console.log((SiteConfig.menu))
                //     sessionStorage.setItem('user-menu', JSON.stringify(SiteConfig.menu));
                //     callback({state:0});
                // });


                HttpUtil.get('project/list', {projectNo: data.defaultProjectNo}).success((res) => {
                    SiteConfig.account.lat = res.data[0].lat;
                    SiteConfig.account.lng = res.data[0].lng;
                    SiteConfig.account.projectName = res.data[0].projectName;
                    SiteConfig.account.projectId = res.data[0].Id;

                    SiteConfig.menu = SiteConfig.Menu_Safe;
                    sessionStorage.setItem('user-menu', JSON.stringify(SiteConfig.menu));

                    console.log('SiteConfig.account', SiteConfig.account);
                    sessionStorage.setItem('user-account', JSON.stringify(SiteConfig.account));
                    callback({state: 0});
                })

            });
        }
    };
}

function parseMenu(data, pid) {

    const result = []
    let temp = []
    for (let i = 0; i < data.length; i++) {
        if (data[i].ParentID === pid) {
            const obj = {
                name: data[i].Text,
                url: data[i].ResponseUrl,
                index: data[i].Id
            }
            temp = this.parseMenu(data, data[i].Id)
            if (temp.length > 0) {
                obj.child = temp
            }
            result.push(obj)
        }
    }
    return result
}

function logout() {
    sessionStorage.removeItem('user-account');
    sessionStorage.removeItem('user-menu');
    return {
        "success": function (callback) {
            callback();
        }
    };
}


//#endregion

